package com.yssw.store.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yssw.common.annotation.Anonymous;
import com.yssw.model.vo.store.StoreVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yssw.common.annotation.Log;
import com.yssw.common.core.controller.BaseController;
import com.yssw.common.core.domain.AjaxResult;
import com.yssw.common.enums.BusinessType;
import com.yssw.store.domain.DistributionStore;
import com.yssw.store.service.IDistributionStoreService;
import com.yssw.common.utils.poi.ExcelUtil;
import com.yssw.common.core.page.TableDataInfo;

/**
 * 门店分布城市Controller
 *
 * @author yssw
 * @date 2023-03-28
 */
@Anonymous
@RestController
@RequestMapping("/store/store")
public class DistributionStoreController extends BaseController {
    @Autowired
    private IDistributionStoreService distributionStoreService;

    /**
     * 查询门店分布城市列表
     */
//    @PreAuthorize("@services.hasPermi('store:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(DistributionStore distributionStore) {
        startPage();
        List<DistributionStore> list = distributionStoreService.selectDistributionStoreList(distributionStore);
        return getDataTable(list);
    }


    /**
     * 查询门店分布城市列表并根据城市名称分组
     */
//    @PreAuthorize("@services.hasPermi('store:store:list')")
    @GetMapping("/listCity")
    public TableDataInfo list() {
        startPage();
        List<StoreVo> list = distributionStoreService.selectStoreGroupList();
        return getDataTable(list);
    }

    /**
     * 导出门店分布城市列表
     */
//    @PreAuthorize("@ss.hasPermi('store:store:export')")
    @Log(title = "门店分布城市", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DistributionStore distributionStore) {
        List<DistributionStore> list = distributionStoreService.selectDistributionStoreList(distributionStore);
        ExcelUtil<DistributionStore> util = new ExcelUtil<DistributionStore>(DistributionStore.class);
        util.exportExcel(response, list, "门店分布城市数据");
    }

    /**
     * 获取门店分布城市详细信息
     */
//    @PreAuthorize("@ss.hasPermi('store:store:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(distributionStoreService.selectDistributionStoreById(id));
    }

    /**
     * 新增门店分布城市
     */
//    @PreAuthorize("@ss.hasPermi('store:store:add')")
    @Log(title = "门店分布城市", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DistributionStore distributionStore) {
        return toAjax(distributionStoreService.insertDistributionStore(distributionStore));
    }

    /**
     * 修改门店分布城市
     */
//    @PreAuthorize("@ss.hasPermi('store:store:edit')")
    @Log(title = "门店分布城市", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DistributionStore distributionStore) {
        return toAjax(distributionStoreService.updateDistributionStore(distributionStore));
    }

    /**
     * 删除门店分布城市
     */
//    @PreAuthorize("@ss.hasPermi('store:store:remove')")
    @Log(title = "门店分布城市", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(distributionStoreService.deleteDistributionStoreByIds(ids));
    }
}
